package com.rpoonolly.simplegame.core.aabb.tests;

import javax.vecmath.Vector2d;

import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;

import com.rpoonolly.simplegame.core.CollisionDetector;
import com.rpoonolly.simplegame.core.Entity;
import com.rpoonolly.simplegame.core.aabb.AABBCollision;
import com.rpoonolly.simplegame.core.aabb.AABBCollisionManager;
import com.rpoonolly.simplegame.core.aabb.AABBEntity;

public class AABBSweptCollisionTest<E extends Entity> {
	private AABBEntity staticEntity, dynamicEntity;
	private Vector2d direction;
	private CollisionDetector<AABBEntity, AABBCollision> collisionDetector;
	
	public AABBSweptCollisionTest() {
		AABBCollisionManager collisionMngr = new AABBCollisionManager();
		
		staticEntity = new AABBEntity(50, 50, 100, 100);
		dynamicEntity = new AABBEntity(0, 0, 25, 25);
		
		collisionDetector = collisionMngr;
		direction = new Vector2d();
	}
	
	@Before
	public void setup() {
		dynamicEntity.setX(0);
		dynamicEntity.setY(0);
		
		staticEntity.setX(50);
		staticEntity.setY(50);
		
		direction.x = 0;
		direction.y = 0;
	}
	
	@Test
	public void testCollision_Passing_Right() {
		dynamicEntity.setY(100);
		direction.x = 200;
		
		Assert.assertNotNull(collisionDetector.collisionDetect(staticEntity, dynamicEntity, direction));
	}
	
	@Test
	public void testCollision_Passing_Left() {
		dynamicEntity.setY(100);
		dynamicEntity.setX(200);
		direction.x = -200;

		Assert.assertNotNull(collisionDetector.collisionDetect(staticEntity, dynamicEntity, direction));
	}
	
	@Test
	public void testCollision_Passing_Down() {
		dynamicEntity.setX(100);
		dynamicEntity.setY(200);
		direction.y = -200;
		
		Assert.assertNotNull(collisionDetector.collisionDetect(staticEntity, dynamicEntity, direction));
	}
	
	@Test
	public void testCollision_Passing_Up() {
		dynamicEntity.setX(100);
		direction.y = 200;

		Assert.assertNotNull(collisionDetector.collisionDetect(staticEntity, dynamicEntity, direction));
	}
}
